package cn.oppexecise;

import java.util.Scanner;

/**
 * @author SWJ
 * @create 2021-06-10 19:01
 * 测试异常2
 */
public class ExceptionDemo2 {
    public static void main(String[] args) {
        method4();
    }

    private static void method4() {
        System.out.println("请输入一个数");
        int i = new Scanner(System.in).nextInt();
        /**提示输入第二个数*/
        System.out.println("输入第二个数");
        int j = new Scanner(System.in).nextInt();
        System.out.println(i / j);
        try{
        double result= divide(i,j);
        //创建divide方法传入参数i,j
            System.out.println(result);
        }catch (Exception e){
            System.out.println("出现异常");
        }
    }

    private static double divide(int i, int j) {
        if (j==0){
            ArithmeticException e=new ArithmeticException("/by zero");

        }
        return i/j;
    }
}
